An instance can be moved by giving it a speed, by setting its position, or by handing it a path to follow - three different jobs with different rules.
Every instance - one copy of an object placed in a room, such as one enemy or one coin - has a position: x and y, measured in pixels. The room's top-left corner is (0, 0): x counts pixels across from the room's left edge and y counts pixels down from its top edge (see Where (0, 0) is). x grows to the right. y grows downward, the way a screen counts, so a bigger y is lower on the screen.
Moving an instance means changing x and y. There are only a few ways to do it, and this page sorts them by what you are trying to get:
| You want | Use | Who does the moving | Does it stop at walls |
|---|---|---|---|
| A steady drift, a fall, a thrown object | a velocity: speed/direction or hsp/vsp | the engine, every frame, by itself | no |
| A jump to an exact spot, or a one-off nudge | x/y directly, or move_to, move_step, move_snap, move_wrap | you, once, when you call it | no |
| Walking that respects walls | move_slide, move_slide_solid, move_bounce | you, every frame you call it | yes |
| Following a shape drawn in advance | a path - see Paths | the engine, along the path | no |
| Gliding to a spot over a set time, speeding up or braking on the way | a tween - tween_to, see Tweens | the engine, until it arrives | no |
A frame is one picture of the game. The GBA shows 60 of them a second, and every speed on this page is measured in pixels per frame. A speed of 1 crosses the 240-pixel-wide screen in four seconds. A speed of 4 does it in one.
Give an instance a speed and it moves by that much on every frame from then on, with no further code. Two pairs of variables do this, and they are two views of the same motion:
hsp and vsp - horizontal and vertical speed. Positive hsp is right, positive vsp is down. This suits movement along the room's axes: a strafe, a platformer's walk.speed and direction - how fast, and which way, in degrees. 0 is east and 90 is up. Turning a bigger angle turns counterclockwise. This suits anything that aims: a bullet fired at a target.You may write to either pair. The engine keeps the other pair in step, so reading speed after setting hsp gives a sensible answer. If you write to a pair this frame, that pair wins. Choose one pair for an instance and stay with it. direction comes from a table, so it is accurate to about a tenth of a degree, not exact.
// Step event of a character that strafes left and right
hsp = btn_dx() * 1.5; // -1, 0 or 1 from the d-pad, times 1.5 pixels a frameTwo more variables act on a velocity for you:
gravity adds that much speed every frame, toward gravity_dir. gravity_dir starts at 270, straight down. Gravity keeps adding, so an instance falls faster each frame until you reset its vsp yourself - on landing, say.friction takes that much off speed every frame, until it reaches 0. A speed of 3 with a friction of 0.5 stops in six frames. Friction works on speed, so use it with speed/direction.The engine applies all of this in the Movement step of every frame, after your Step events. Set a speed in Step and it takes effect that same frame. See The order of a frame.
None of this looks at walls unless the instance lands on solids. An instance moving by velocity goes straight through anything solid, unless its Lands on solids box is ticked (or lands_on_solids is true): then it stops on solid tiles and solid objects, standing right on top of a floor with on_ground true, stopping under a ceiling, and sliding along a wall.
Writing to x or y puts the instance there at once. Nothing is animated between the old spot and the new one. A few functions do common versions of this:
move_to(x, y) jumps to a spot.move_step(distance) steps that far along the current direction. It is a single nudge. It does not set a speed, so nothing continues on later frames.move_snap(grid_x, grid_y) rounds the position to the nearest grid square. A size of 0 leaves that axis alone.move_wrap(left, top, right, bottom, margin) sends an instance that has left a rectangle out past one side back in from the opposite side. Passing 0 as the margin wraps it the moment it leaves.None of these check for walls either.
A function is a named action you call with values in brackets. Three of them move an instance and check the room's collision - its solid tiles and obstacles - while doing it:
move_slide(dx, dy) moves by that much and, when it hits something, slides along it instead of stopping dead. It also slips around corners. This is what top-down walking wants.move_slide_solid does the same, and also treats live solid instances of the object types you name - as many as you like - as walls.move_bounce() moves by the instance's own hsp/vsp. When it is blocked on one axis, it reverses that axis's speed. This is a ball off a wall.Here is a top-down walker. It reads the d-pad as two numbers and hands them to move_slide, which stops it at walls and slides it along them:
// Step event of a top-down walker (hsp and vsp stay at 0)
move_slide(btn_dx() * 1.5, btn_dy() * 1.5);Call these from Step, every frame. move_slide is given the distance directly, so leave hsp and vsp at 0 while you use it. Otherwise the automatic velocity movement also runs and moves the instance a second time. move_bounce is the opposite case: it works from hsp/vsp, which stay set, so the automatic movement also applies them and the instance covers about double the distance you might expect.
Velocity answers "how fast and which way, right now." A path answers a different question: "follow this exact route." It is a list of points drawn once in the editor. An instance told to follow it goes point to point, and a patrolling guard, a moving platform or a conveyor of pickups needs no code beyond the start call. Paths covers what a path is and what happens when the instance reaches the end.
Two things to know about how the two systems meet:
x and y outright. While an instance follows a path, its hsp/vsp/speed have no visible effect, so leave them alone. gravity still adds to vsp in the background, so a fall can begin all at once when the path stops.path_x_at/path_y_at and walk toward them with move_slide.| Entry | What it is |
|---|---|
hsp, vsp | horizontal and vertical speed, pixels per frame |
speed, direction | speed along an angle, in degrees |
gravity, gravity_dir | speed added every frame, and which way |
friction | speed removed every frame, until 0 |
lands_on_solids, on_ground | stop on solid tiles and objects, and whether it is standing on something |
move_to, move_step, move_snap, move_wrap | placing, with no wall checks |
move_slide, move_slide_solid, move_bounce | moving, with wall checks |
solid and collides cover how the engine decides what counts as a wall. The functions that read a path are listed on the Paths page.